<template>
	<view class="user">
    <statusBar></statusBar>
		<logo></logo>
    <view class="userbg">
    	<image :src="userInfo.Avatar" mode=""></image>
      <text>{{userInfo.UserName}}</text>
    </view>
    <view style="height:10px;background-color: #f2f2f2;"></view>
    <uni-list>
      <!--  #ifdef  MP-WEIXIN -->
      <uni-list-item @click="goNotice" title="消息通知" thumb="../../../static/img/user/xiaoxi.png"></uni-list-item>
      <!--  #endif -->
      <uni-list-item @click="goCuoti" title="我的错题" thumb="../../../static/img/user/cuoti.png"></uni-list-item>
      <uni-list-item @click="goShoucang" title="我的收藏" thumb="../../../static/img/user/shoucang.png"></uni-list-item>
	  <!-- 1.1.2 -->
	  <uni-list-item @click="goJiangjie" title="我的讲解" thumb="../../../static/img/user/wodejiangjie.png"></uni-list-item>
	  <!--  -->
      <uni-list-item @click="goFenxi" title="成绩分析" thumb="../../../static/img/user/fenxi.png"></uni-list-item>
      <uni-list-item @click="goSetup" title="个人设置" thumb="../../../static/img/user/yonghu.png"></uni-list-item>
    </uni-list>
    
    <view class="loginout">
    	<button @click="loginOut" v-show="userTokon == true">退出登录</button>
      <button @click="goLogin" v-show="userTokon == false">登录</button>
    </view>
    <uni-popup :show="type === 'middle'" position="middle" mode="fixed" :msg="msg" @hidePopup="togglePopup('')"></uni-popup>
	</view>
</template>

<script>
  import logo from "@/components/logo.vue"
  import uniList from '@/components/uni-list/uni-list.vue'
  import uniListItem from '@/components/uni-list-item/uni-list-item.vue'
  import statusBar from "@/components/status-bar.vue"
	export default {
    components:{
    	logo,
      uniList,
      uniListItem,
      statusBar
    },
		data() {
			return {
				userInfo: [],
        type: '',
        userTokon: true
			};
		},
    onShow() {
      if(uni.getStorageSync('token') == null || uni.getStorageSync('token') == undefined || uni.getStorageSync('token') == ''){
        this.userTokon = false;
        this.userInfo = [];
      }else{
        this.userTokon = true;
        this.getUserInfo();
      }
    },
    onLoad: function (option) { 
        if(uni.getStorageSync('token') == null || uni.getStorageSync('token') == undefined || uni.getStorageSync('token') == ''){
          this.userTokon = false;
          this.userInfo = [];
        }else{
          this.userTokon = true;
          this.getUserInfo();
        }
    },
    watch:{
      
    },
    created() {
    	
    },
    methods:{
      getUserInfo: function(){
        uni.request({
          method: 'GET',
          header: {
            'Content-Type': 'application/json',
            'Authorization': uni.getStorageSync('token')
          },
          url: this.apiUrl + 'api/student/personal/GetUserInfo', 
          data: {},
          success: res => {
            if(res.statusCode == 200){
              this.userInfo = res.data.data;
              this.userInfo.Avatar = this.apiUrl + this.userInfo.Avatar; 
              this.userInfo.Avatar = this.userInfo.Avatar.replace(/\\/g,'\/');
            }else{
//               this.msg = '未知错误';
//               this.togglePopup('middle');
            }
            
          }
        });
      },
      goLogin: function(){
        uni.navigateTo({
        	url: '../../login/login'
        })
      },
      goNotice: function(){
        if(uni.getStorageSync('token') == null || uni.getStorageSync('token') == undefined || uni.getStorageSync('token') == ''){
          uni.reLaunch({
          	url: '../../login/login'
          })
        }else{
          uni.navigateTo({
          	url: 'notice/notice'
          })
        }
      },
      goCuoti: function(){
        if(uni.getStorageSync('token') == null || uni.getStorageSync('token') == undefined || uni.getStorageSync('token') == ''){
          uni.reLaunch({
          	url: '../../login/login'
          })
        }else{
          uni.navigateTo({
          	url: 'usercuoti/usercuoti'
          })
        }
      },
      goShoucang: function(){
        if(uni.getStorageSync('token') == null || uni.getStorageSync('token') == undefined || uni.getStorageSync('token') == ''){
          uni.reLaunch({
          	url: '../../login/login'
          })
        }else{
          uni.navigateTo({
          	url: 'usershoucang/usershoucang'
          })
        }
      },
	  goJiangjie: function(){
		  // 1.1.2
		  if(uni.getStorageSync('token') == null || uni.getStorageSync('token') == undefined || uni.getStorageSync('token') == ''){
		    uni.reLaunch({
		    	url: '../../login/login'
		    })
		  }else{
		    uni.navigateTo({
		    	url: 'userjiangjie/userjiangjie'
		    })
		  }
	  },
      goFenxi: function(){
        if(uni.getStorageSync('token') == null || uni.getStorageSync('token') == undefined || uni.getStorageSync('token') == ''){
          uni.reLaunch({
          	url: '../../login/login'
          })
        }else{
          uni.navigateTo({
          	url: 'userfenxi/userfenxi'
          })
        }
      },
      goSetup: function(){
        if(uni.getStorageSync('token') == null || uni.getStorageSync('token') == undefined || uni.getStorageSync('token') == ''){
          uni.reLaunch({
          	url: '../../login/login'
          })
        }else{
          uni.navigateTo({
          	url: 'usersetup/usersetup'
          })
        }
      },
      loginOut: function(){
        this.msg = '退出成功';
        this.togglePopup('middle');
        let vm = this;
        uni.setStorage({
            key: 'token',
            data: '',
            success: function () {
              setTimeout(() => {
                uni.navigateTo({
                  url:'../../login/login'
                })
                vm.togglePopup('false');
              }, 500)
              
            }
        });
      },
    }
	}
</script>

<style scoped>
  .line{
    height: 15upx;
  }
  .userbg{
    width: 100%;
    height: 392upx;
    background-color: #27b28b;
    overflow: hidden;
  }
  .userbg image{
    width: 160upx;
    height: 160upx;
    display: block;
    border-radius: 100px;
    border: 4upx solid #FFFFFF;
    margin: 90upx auto 40upx auto;
  }
  .userbg text{
    font-size: 30upx;
    color: #FFFFFF;
    display: block;
    text-align: center;
  }
  .loginout{
    text-align: center;
    margin: 60upx auto 0 auto;
  }
  .loginout button{
    width: 702upx;
    height: 88upx;
    border-radius: 8px;
    background-color: #FFFFFF;
    color: #333333;
    font-size: 32upx;
    border: none;
  }
</style>
